import {
    Column,
    CreateDateColumn,
    DeleteDateColumn,
    Entity,
    PrimaryGeneratedColumn,
    Unique,
    UpdateDateColumn
} from "typeorm";
import { AutoMap } from "@automapper/classes";
import { Role } from "@/enums";

@Entity("accounts")
@Unique("accounts__userName__uk", ["userName"])
@Unique("accounts__email__uk", ["email"])
export class Account {
    @AutoMap()
    @PrimaryGeneratedColumn({ primaryKeyConstraintName: "accounts__id__pk" })
    id: number;

    @AutoMap()
    @Column({ type: "jsonb", default: [Role.Student] })
    roles: Role[];

    @AutoMap()
    @Column()
    userName: string;

    @AutoMap()
    @Column()
    passwordHash: string;

    @AutoMap()
    @Column({ nullable: true })
    firstName: string;

    @AutoMap()
    @Column({ nullable: true })
    lastName: string;

    @AutoMap()
    @Column()
    email: string;

    @AutoMap()
    @CreateDateColumn({ type: "timestamp" })
    createdAt: Date;

    @AutoMap()
    @UpdateDateColumn({ type: "timestamp" })
    updatedAt: Date;

    @DeleteDateColumn({ type: "timestamp" })
    deletedAt: Date;

    @AutoMap()
    @Column({ default: false })
    needChangePassword: boolean;

    @AutoMap()
    @Column({ default: false })
    isBlocked: boolean;
}
